* **************************************************************************** *
* Sierra Leone - Social Signaling and Childhood Immunization                   *
* Others' Inferences about Types Conditional on Vaccination Decisions                                                        *
* **************************************************************************** *
/*
** Purpose:    Table: Others' Inferences about Types Conditional on Vaccination Decisions

*/
********************************************************************************
********************************************************************************

* How would they view you if you missed to take your child for vaccinations? 

	use  "${Replicate_SocialSignals_dtaInter}/Endline_Survey_Data.dta", clear

	* Merge in the ANC treatment status:
	merge m:m clinic  using  "${Replicate_SocialSignals_dtaInter}/MasterData_PilotClinics.dta", gen(ANCtreat)


	* Label the treatment variable:
	lab var treat3   "Signal at 4"
	lab var treat4   "Signal at 5"
	lab var treat2   "Uninformative Bracelet"

	* --------------------------------------------------------------------------
	* Coding the Outcomes conditional:

	local   MissedVars  = " careless notknow lazy busymother poor nothing"

	summ     concerned `MissedVars'

	foreach  reason of local MissedVars {
		replace `reason' = .                      if concerned == 0
	}


	* --------------------------------------------------------------------------
	* Demean control variables:

	tab     arm_anc, gen(anc)

	foreach control in anc2 anc3 anc4  {
		* For full sample:
		sum  `control' if intervention_arm==1, detail
		gen  `control'_full_dm = `control' - `r(mean)'

		* Restricted sample:
		sum  `control'                                      if concerned == 1 & intervention_arm==1 , detail
		gen  `control'_dm      = `control' - `r(mean)'      if concerned == 1
	}

	tab     education_cat, gen(educ)

	local   ControlVars = " mother_age_w01 educ2 educ3 farm  birth2 birth3 birth4 birth5 "

	foreach control of local  ControlVars  {
		* For full sample:
		summ `control'  if intervention_arm==1, detail
		gen  `control'_full_dm = `control' - `r(mean)'

		* for restricted sample:
		summ `control'                                      if concerned == 1 & intervention_arm==1, detail
		gen  `control'_dm      = `control' - `r(mean)'      if concerned == 1
	}


	local   ControlVars = " mother_age_w01_dm educ2_dm educ3_dm farm_dm birth2_dm birth3_dm birth4_dm birth5_dm "
	local   ANC_dm      = " anc2_dm anc3_dm anc4_dm "


	summ   concerned `ControlVars' `ANC_dm'


	* --------------------------------------------------------------------------

	* Full Sample Control Variables:
	local  ControlVars_full = " mother_age_w01_full_dm educ2_full_dm educ3_full_dm farm_full_dm " + ///
	" birth2_full_dm birth3_full_dm birth4_full_dm birth5_full_dm "
	local  ANC_dm_full      = " anc2_full_dm anc3_full_dm anc4_full_dm "


	* Restricted sample (only concerned = 1)
	local  ControlVars      = " mother_age_w01_dm educ2_dm educ3_dm farm_dm birth2_dm birth3_dm birth4_dm birth5_dm "
	local  ANC_dm           = " anc2_dm anc3_dm anc4_dm "


	local  OutcomeVars = " careless notknow lazy busymother poor nothing "

	eststo clear
	areg   concerned  treat3 treat4 treat2      `ControlVars_full'    `ANC_dm_full', absorb(strata) vce(bootstrap , reps(${RepsNum}) seed(${seed}) cluster(clinic))
	eststo
	test   treat3 = treat2
	estadd scalar treat2_treat3 = r(p)
	test   treat3 = treat4
	estadd scalar treat3_treat4 = r(p)
	test   treat2 = treat4
	estadd scalar treat2_treat4 = r(p)
	test   treat2 treat3 treat4
	estadd scalar bracelets     = r(p)
	estadd local Obs            = "`e(N)'"
	estadd scalar C_mean        = _b[_cons]
	eststo model_concerned

	foreach outcome of local OutcomeVars {
		areg   `outcome' treat3 treat4 treat2      `ControlVars'    `ANC_dm', absorb(strata) vce(bootstrap , reps(${RepsNum}) seed(${seed}) cluster(clinic))
		eststo
		test   treat3 = treat2
		estadd scalar treat2_treat3 = r(p)
		test   treat3 = treat4
		estadd scalar treat3_treat4 = r(p)
		test   treat2 = treat4
		estadd scalar treat2_treat4 = r(p)
		test   treat2 treat3 treat4
		estadd scalar bracelets     = r(p)
		estadd local Obs            = "`e(N)'"
		estadd scalar C_mean        = _b[_cons]
		eststo model_`outcome'
	}

	esttab  ///
	model_concerned                                                   ///
	model_careless model_notknow model_lazy                           ///
	model_busymother model_poor  model_nothing                        ///
	using "${Replicate_SocialSignals_ATables}/Table_ViewMissedVaccines_raw.tex",         ///
	prehead("\begin{tabular}{l*{8}{c}} \toprule \\"                   ///
	"\multicolumn{1}{l}{\textbf{\textbf{Dependent Variable:}}} & \multicolumn{1}{c}{\textbf{Is anyone concerned about}}  & \multicolumn{6}{c}{\textbf{How would they view you if you missed to take your child for immunization?}}   \\"  ///
	"                                                          & \multicolumn{1}{c}{\textbf{your child’s immunization?}} & \multicolumn{1}{c}{\textbf{Careless}} & \multicolumn{1}{c}{\textbf{Ignorant}} & \multicolumn{1}{c}{\textbf{Lazy}}  & \multicolumn{1}{c}{\textbf{Busy}}  & \multicolumn{1}{c}{\textbf{Poor}} & \multicolumn{1}{c}{\textbf{No judgement}} \\")  ///
	scalars("C_mean       Control Group mean"                             ///
	"Obs          Observations"                                   ///
	"treat2_treat3 \(S_{4}\) \(>\) 0: p(UI = S4)"                 ///
	"treat2_treat4 \(S_{5}\) \(>\) 0: p(UI = S5)"                 ///
	"treat3_treat4 p(S4 = S5)"                                    ///
	"bracelets Joint F-Test")                                     ///
	substitute(\(S\_{4}\) \(S_{4}\)  \(S\_{5}\) \(S_{5}\))                ///
	keep(_cons treat3 treat4 treat2)                                      ///
	varlabels(_cons "Control Group mean")                                 ///
	sfmt(3) ${StarsOpt}  nomtitles                                        ///
	addnotes("") label b(3) se(3)  nobaselevels noconstant noobs          ///
	nolines posthead("\midrule") postfoot("\bottomrule \end{tabular}") tex  ///
	replace

	filefilter "${Replicate_SocialSignals_ATables}/Table_ViewMissedVaccines_raw.tex"      ///
	"${Replicate_SocialSignals_ATables}/Table_ViewMissedVaccines_Controls_Cond.tex", from("[1em]") to(" ") replace
	erase	     "${Replicate_SocialSignals_ATables}/Table_ViewMissedVaccines_raw.tex"



* **************************************************************************** *
* End of the Dofile !!!
* **************************************************************************** *
